#include <stdbool.h>
#include <stdio.h>

#include "treeUtils.h"

bool fun(struct TreeNode *root, long low, long high)
{
    if (root == NULL) {
        return true;
    }
    long num = root->val;
    if (num <= low || num >= high) {
        return false;
    }
    return fun(root, low, num) && fun(root->right, num, high);
}

bool isValidBST(struct TreeNode *root)
{
    return fun(root, LONG_MIN, LONG_MAX);
}

int main()
{
    char str[] = "[5,1,4,null,null,3,6]";
    printf("%s\n", "start strtok string.");
    int count = 0;
    char retStrArr[100][10] = {0};
    getNum(str, retStrArr, &count);
    int numArr[9] = {0};
    for (int i = 0; i < count; ++i) {
        printf("%s\n", retStrArr[i]);
        numArr[i] = atoi(retStrArr[i]);
    }
    printf("%s\n", "end strtok string.");

    struct TreeNode *root = malloc(sizeof(struct TreeNode));
    root->val = numArr[0];
    root->left = NULL;
    root->right = NULL;
    bfsBuildTree(root, numArr, count);
    bool ret = isValidBST(root);
    printf("\n%s", ret == 0 ? "false" : " true");
}
